<script setup>
import hotSvg from "@/components/hotSvg.vue"
import {rolesList,roleType} from "@/utils/home.js"
import { ref } from "vue";
const typeKeys = Object.keys(roleType).sort((a, b) => Number(a) - Number(b));

// 2. 遍历排序后的键，提取对应的值（类别名称），生成最终数组
const categories = ref(typeKeys.map(key => roleType[key]));

// 当前激活的索引
const activeIndex = ref(0);
const handleChange = (index)=>{
    activeIndex.value = index
    console.log(activeIndex.value)
}
</script>

<template>
  <div class="mainlist">
    <div class="hot">
      <span class="title">AI模拟</span>
      <span class="info">智创角色&nbsp;&nbsp;&nbsp;&nbsp;模拟换新</span>
    </div>
    <div class="category-nav">
    <button 
      v-for="(item, index) in categories" 
      :key="index"
      class="category-btn"
      :class="{ active: activeIndex === index }"
      @click="handleChange(index)"
    >
      {{ item }}
    </button>
  </div>
    <div class="list">
      <el-row :gutter="20">
        <el-col :span="4" :offset="0" class="container" v-for="(item,index) in rolesList" :key="index">
          <el-card shadow="hover">
            <div class="img">
              <img :src="item.img" alt="" class="roles" />
            </div>
            <div class="cardright">
              <h4>{{item.name}}</h4>
              <p>{{item.info}}</p>
              <p><hotSvg /><span>{{item.hot}}</span></p>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
<style scoped>
.mainlist {
  padding: 0px 20px;
}
.mainlist .title {
  font-size: 30px;
  color: #333;
  font-weight: 400;
}
.mainlist .info {
  margin-left: 40px;
  font-size: 16px;
  color: #a1a1a1;
}
/* HotItem.vue 组件内样式 */
.container {
  position: relative;
}

::v-deep .el-card {
  padding: 0px;
  margin-top: 10px;
  background-color: #fff;
}

.el-card__body {
  display: flex;
}

.img .roles {
  width: 75px;
  height: 75px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid #fff;
}

.cardright {
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
}

.cardright h4 {
  font-size: 18px;
  font-weight: 500;
  margin: 0 0 8px 0;
}

.cardright p {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 78%;
  font-size: 14px;
  color: #9e9e9e;
  margin: 0; 
}
.category-nav {
  display: flex;
  gap: 4px;
  padding: 10px 20px;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none; /* 隐藏滚动条 */
}

/* 隐藏滚动条但保留功能 */
.category-nav::-webkit-scrollbar {
  display: none;
}

.category-btn {
  padding: 6px 16px;
  background: transparent;
  border: none;
  border-radius: 16px;
  font-size: 14px;
  color: #6B7280;
  cursor: pointer;
  transition: all 0.2s ease;
}


.category-btn.active {
  background-color: #409EFF;
  color: #FFFFFF;
}

.category-btn:not(.active):hover {
  background-color: #F0F7FF;
  color: #409EFF;
}

.category-btn:active {
  transform: scale(0.96);
}
</style>
